package main

import (
	"fmt"
	"gitee.com/ao-iot/ao-iot-core/plugins-project/hepeichun/web/config/routers"
	"github.com/gin-gonic/gin"
	"log"
)

const (
	pluginName    = "hepeichun@web"
	pluginVersion = 0x00010000
)

func init() {
}

func Load(register func(name string, version uint64) error) error {
	err := register(pluginName, pluginVersion)
	if err != nil {
		log.Println(err.Error())
		return err
	}
	log.Printf("loading %s plugin\n", pluginName)
	go func() {
		run()
	}()
	return nil
}

func Unload() error {
	fmt.Printf("unload %s, version: 0x%x\n", pluginName, pluginVersion)
	return nil
}

func run() {
	r := gin.Default()

	//注册路由
	for s, m := range routers.Get() {
		for s2, handlerFunc := range m {
			r.Handle(s, s2, handlerFunc)
		}
	}

	r.Run(":8080")
}
